package com.zhiwang.xiaoqu.mvp.model.room

import androidx.room.*
import com.google.gson.annotations.SerializedName
import io.reactivex.Flowable

@Entity(tableName = "User")
class User constructor(
    @PrimaryKey var userid: String,
    var token: String,
    var username: String,
    var phone: String,
    @Embedded
    @SerializedName("bind")
    var bindInfo: BindInfo
){

}

class BindInfo(
    var pay_password: Boolean,
    @SerializedName("weixinpay")
    var weixinHasBind: Boolean,
    @SerializedName("weixinpay_nickname")
    var weixinNickName: String,
    @SerializedName("alipay")
    var alipayHasBind: Boolean,
    @SerializedName("alipay_account")
    var alipayAccount: String,
    @SerializedName("alipay_username")
    var alipayName: String
)

@Dao
interface UserDao {


    @Query("SELECT * FROM User")
    fun getUsers(): Flowable<List<User>>

    @Query("SELECT * FROM User")
    fun getUsersSync(): List<User>

    @Query("select * from User limit 1")
    fun getFirstUser(): User

    @Query("DELETE FROM User")
    fun deleteAll()

    @Update
    fun updateUser(user: User)

    @Update
    fun updateUsers(users: List<User>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addUser(user: User)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addUser(users: List<User>)
}